//
//  App_SetBadgeHandler.swift
//  mall-ios
//
//  Created by Meak Tsui on 2019/1/7.
//  Copyright © 2019 Meak Tsui. All rights reserved.
//

import Foundation
import MTHybrid
import Shared

class App_SetBadgeHandler: MTEventHandler {
    var ns: Ns {
        return .App
    }
    
    var action: Api {
        return .SetBadge
    }
    
    func handler(_ msg: MTHybridMsg) {
        guard let num = (msg.params["num"] as? NSNumber)?.intValue else {
            dPrint("未找到参数num")
            msg.callbackClosure?(0)
            return
        }
        let preNum = UIApplication.shared.applicationIconBadgeNumber
        UIApplication.shared.applicationIconBadgeNumber = num >= 0 ? num : preNum
        msg.callbackClosure?(preNum)
    }
    
    
}
